from typing import Optional
from pydantic import BaseModel, Field
from datetime import datetime

class StudentBase(BaseModel):
    """学生基础信息"""
    user_id: int = Field(..., description="关联的用户ID")
    academy: str = Field(..., description="学院")
    major: str = Field(..., description="专业")
    class_: str = Field(..., description="班级")

class StudentCreate(BaseModel):
    """创建学生的请求模型"""
    academy: str = Field(..., description="学院")
    major: str = Field(..., description="专业")
    class_: str = Field(..., description="班级")


class StudentUpdate(StudentBase):
    """更新学生的请求模型"""
    academy: Optional[str] = Field(None, description="学院")
    major: Optional[str] = Field(None, description="专业")
    class_: Optional[str] = Field(None, description="班级")

class StudentInDB(StudentBase):
    """数据库中的学生模型"""
    id: int
    user_id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True

class StudentResponse(BaseModel):
    """学生响应模型"""
    user_id: int
    academy: str
    major: str
    class_: str = Field(..., alias="class")

    class Config:
        from_attributes = True